package com.zhouyibike.uu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.entity.ProductPayTypeResult;

import java.util.List;

/**
 * Created by cc on 2017/5/3.
 */

public class BuydanchetypeAdapter2 extends BaseAdapter {
    private Context context;
    private List<ProductPayTypeResult.DataBean.PayTypesBean> list;
    private int postion=-1;
    public BuydanchetypeAdapter2(Context context, List<ProductPayTypeResult.DataBean.PayTypesBean> list) {
        this.context = context;
        this.list = list;
    }
    public  void setList(List<ProductPayTypeResult.DataBean.PayTypesBean> list){
        this.list = list;
        notifyDataSetChanged();
    }
    public  void setchecked(int postion){
        this.postion = postion;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {// 如果是第一次显示该页面(要记得保存到viewholder中供下次直接从缓存中调用)
            convertView= LayoutInflater.from(context).inflate(R.layout.item_buydanchelist2,null);
            holder = new ViewHolder();
            // 以下为保存这一屏的内容，供下次回到这一屏的时候直接refresh，而不用重读布局文件
            holder.tv = (TextView) convertView.findViewById(R.id.tv_itemtype);
            convertView.setTag(holder);
        } else {// 如果之前已经显示过该页面，则用viewholder中的缓存直接刷屏
            holder = (ViewHolder) convertView.getTag();
        }
        if (list.get(position).getYiQuan()!=0&&list.get(position).getMoney()==0){
            holder.tv.setText("翼券"+list.get(position).getYiQuan());
        }else if (list.get(position).getYiQuan()!=0&&list.get(position).getMoney()!=0){
            holder.tv.setText("￥"+list.get(position).getMoney()+"+"+"翼券"+list.get(position).getYiQuan());
           // holder.tv.setText("￥"+1118.01+"+"+"翼券"+100);
        }else{
            holder.tv.setText("￥"+list.get(position).getMoney());
        }
        if(postion==position){
            holder.tv.setBackgroundResource(R.drawable.buydanche_pressed2);
            holder.tv.setTextColor(context.getResources().getColor(R.color.bg_main_white));
        }else{
            holder.tv.setBackgroundResource(R.drawable.buydanche_notpressed2);
            holder.tv.setTextColor(context.getResources().getColor(R.color.black80));
        }
        return convertView;
    }

    public final class ViewHolder {
        public TextView tv;
    }
}
